package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.mapper.SetmealDishMapper;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "")
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类 id 查询套餐
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = "setmeal", key = "#categoryId")
    @GetMapping("/list")
    public Result<List> list(Integer categoryId) {
        List<Setmeal> setmeals = setmealService.listByCategoryId(categoryId);
        return Result.success(setmeals);
    }

    /**
     * 根据套餐 id 查询包含的菜品
     * @param setmealId
     * @return
     */
    @GetMapping("/dish/{setmealId}")
    public Result<List> getSetmealDishList(@PathVariable Long setmealId) {
        List<DishItemVO> dishItemVOS = setmealService.selectUserSetmealDishById(setmealId);
        return Result.success(dishItemVOS);
    }
}
